package day17;

import java.io.*;
import java.util.Arrays;

/**
 * @author ZJX
 * @version 1.0
 * @descption
 * @since 2025/10/27 19:52
 */
public class Day14 {

//    public static void main(String[] args) throws IOException {
//        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//        PrintWriter out = new PrintWriter(System.out);
//        HashMap<Character, Integer> map = new HashMap<>();
//        in.nextToken();
//        char[] window = in.sval.toCharArray();
//        in.nextToken();
//        char[] need = in.sval.toCharArray();
//        for (char c : need) {
//            map.put(c, map.getOrDefault(c, 0) + 1);
//        }
//        for (char ch : window){
//            if (map.containsKey(ch)){
//                map.put(ch, map.get(ch)-1);
//                if (map.get(ch) <= 0){
//                    map.remove(ch);
//                }
//            }
//        }
//        if (map.isEmpty()){
//            out.println("Yes");
//        } else {
//            out.println("No");
//        }
//        out.close();
//    }

//    public static void main(String[] args) throws IOException {
//        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//        PrintWriter out = new PrintWriter(System.out);
//        in.nextToken();
//        int n = (int) in.nval;
//        int[] nums = new int[3 * n];
//        for (int i = 0; i < 3 * n; i++) {
//            in.nextToken();
//            nums[i] = (int) in.nval;
//        }
//        Arrays.sort(nums);
//        long sum = 0;
//        for (int i = 0; i < n; i++) {
//            sum += nums[3 * n - 2 - 2 * i];
//        }
//        out.println(sum);
//        out.close();
//    }

    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(System.out);
        in.nextToken();
        int n = (int) in.nval;
        int[] nums = new int[n];
        int maxNum = 0;
        for (int i = 0; i < n; i++) {
            in.nextToken();
            nums[i] = (int) in.nval;
            maxNum = Math.max(maxNum, nums[i]);
        }
        Arrays.sort(nums);
        long[] value = new long[maxNum + 1];
        for (int x : nums) {
            value[x] += x;
        }
        long[] dp = new long[maxNum + 1];
        if (maxNum >= 1) {
            dp[1] = value[1];
        }
        for (int i = 2; i < maxNum + 1; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + value[i]);
        }
        out.println(dp[maxNum]);
        out.close();
    }
}

